package com.mengfx.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mengfx.bean.PostImage;
import com.mengfx.mapper.PostImageMapper;
import com.mengfx.service.PostImageService;
import com.mengfx.service.QiNiuService;
import com.mengfx.vo.ImageVo;
@Service("postImageService")
public class PostImageServiceImpl implements PostImageService {
	
	@Autowired
	private PostImageMapper postImageMapper;
	
	@Autowired
	private QiNiuService qiNiuService;

	public boolean insertPostImage(PostImage bean) {
		// TODO Auto-generated method stub
		return postImageMapper.insertSelective(bean) > 0;
	}

	public List<PostImage> getImagesByPostId(Long postId) {
		// TODO Auto-generated method stub
		return postImageMapper.getImagesByPostId(postId);
	}

	public List<ImageVo> postImagesVoConvertImageVos(Long postId) {
		List<PostImage> list = this.getImagesByPostId(postId);
		List<ImageVo> vos = new ArrayList<ImageVo>();
		if(null != list && list.size() > 0){
			for(PostImage bean :list){
				ImageVo vo = new ImageVo();
				vo.setImgkey(bean.getImage());
				vo.setUrl(qiNiuService.resolveUrl(bean.getImage()));
				vos.add(vo);
			}
		}
		return vos;
	}

	@Override
	public void updatePostId(Long prePostId, Long afterPostId) {
		postImageMapper.updatePostId(prePostId, afterPostId);
	}
	
}
